package ru.spb.osll.myfit.common;

import java.util.Vector;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Table extends PageElement implements IsSerializable {
	private static final long serialVersionUID = -8642682637800639769L;
	private Vector<Vector<TableCell>> m_data = new Vector<Vector<TableCell>>();
	private TableStyle m_style;

	// private String m_sFixureClassName;

	public Table() {
		m_style = TableStyle.UNKNOWN_FIXTURE;
	}

	public Table(TableStyle style) {
		m_style = style;
	}

	public void addLine(Vector<TableCell> currentLine) {
		m_data.add(currentLine);
	}

	public boolean isEmpty() {
		return m_data.size() == 0;
	}

	public void clear() {
		m_data.clear();
	}

	public Vector<Vector<TableCell>> getData() {
		return m_data;
	}

	public TableStyle getStyle() {
		return m_style;
	}

	public void setStyle(TableStyle style) {
		m_style = style;
	}

  @Override
  public PageElementType getType() {
    return PageElementType.TABLE;
  }

	// public String getFixtureClassName() {
	// return m_sFixureClassName;
	// }
	//	
	// public void setFixtureClassName(String sFixtureClassName){
	// this.m_sFixureClassName = sFixtureClassName;
	// }
  
  @Override
  public boolean equals(Object obj) {
    Table table = (Table) obj;
    
    if (m_data.size() != table.getData().size())
      return false;
    
    for (int i=0; i<m_data.size(); i++) {
      if (! equalsLists(m_data.get(i), table.getData().get(i)))
        return false;
    }
    
    return true;
  }
  
  private boolean equalsLists (Vector<TableCell> v1, Vector<TableCell> v2) {
    if (v1.size() != v2.size())
      return false;
    
    for (int i=0; i<v1.size(); i++) {
      if (!v1.get(i).equals(v2.get(i)))
        return false;
    }
    
    return true;
  }

}
